﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Manage/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<QianBuo.Lottery.Web.Models.Account.DetailModel>" %>

<%@ Import Namespace="QianBuo.Lottery.Web.Models.Account" %>
<%@ Import Namespace="Code.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    账变明细
    <% TempData["Surrogate_AccountReport_Serch.Type"] = Model.Serch.Type; %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <% Html.DisableClientValidation(); %>
        <% Html.BeginForm(Url.Route(new {ReturnUrl=Request["ReturnUrl"],act=Request["act"],cont=Request["cont"],arst=Request["arst"] }), Url.Route(new { id = "serchreportform" })); %>
        <table class="table" width="100%">
            <tr class="th">
                <th align="left" colspan="6">
                    &nbsp;查找条件
                </th>
            </tr>
            <tr>
                <td>
                    <label for="Serch_Type">类型:</label>
                    <%=Html.DropDownListFor(p=>p.Serch.Type,Model.Types.OrderBy(p=>p.Text.Length).Each(p=>p.Selected=p.Value==(Model.Serch.Type??(object)"").ToString())) %>
                </td>
                <td>
                    <label for="Serch_MinTime">
                        金额:</label>
                    <input type="text" name="Serch.MinMoney" id="Serch_MinMoney" validate="{number:true,range:[0,999999999],messages:{number:'*',range:'*'}}"
                        class="text80" value='<%=Model.Serch.MinMoney %>' />
                </td>
                <td>
                    <label for="Serch_MaxMoney">
                        至:</label>
                    <input type="text" name="Serch.MaxMoney" id="Serch_MaxMoney" validate="{number:true,range:[0,999999999],messages:{number:'*',range:'*'}}"
                        class="text80" value='<%=Model.Serch.MaxMoney %>' />
                </td>
                <td align="center">
                    <label for="Serch.UserType" id="Serch_UserType">用户组:</label>
                    <%=Html.DropDownListFor(p => p.Serch.UserType, Model.UserTypes.Each(p => p.Selected = p.Text.Equals(Model.Serch.UserType)))%>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="Serch_LoginName">用户:</label>
                    <input type="text" name="Serch.LoginName" id="Serch_LoginName" class="text100" value='<%=Model.Serch.LoginName %>' />
                </td>
                <td>
                    <label for="Serch_StartTime">
                        时间:</label>
                    <input type="text" name="Serch.StartTime" id="Serch_StartTime" onclick="WdatePicker()"
                         class="text80" value='<%=Model.Serch.StartTime.HasValue?Model.Serch.StartTime.Value.ToString("yyyy-MM-dd"):"" %>' />
                </td>
                <td>
                    <label for="Serch_EndTime">
                        至:</label>
                    <input type="text" name="Serch.EndTime" id="Serch_EndTime" onclick="WdatePicker()"
                         class="text80" value='<%=Model.Serch.EndTime.HasValue?Model.Serch.EndTime.Value.ToString("yyyy-MM-dd"):"" %>' />
                </td>
                <td align="center">
                    <input type="submit" value="查找" />
                </td>
            </tr>
        </table>
        <%=Html.HiddenFor(p=>p.PageSize) %>
        <% Html.EndForm(); %>
        <% var orderByFlag = string.IsNullOrEmpty(Model.OrderByType) ? false : Model.OrderByType.Equals("ASC", StringComparison.CurrentCultureIgnoreCase); %>
        <p />
        <table id="report" class="table" width="100%">
            <tr class="th">
                <th width="10%">用户</th>
                <th width="5%">组</th>
                <th width="17%">日期</th>
                <th width="8%">类型</th>
                <th width="5%">
                    <label class='lblOrderBy' onclick="lbl_OrderBy_Click('InMoney','<%=orderByFlag?"DESC":"ASC" %>')">
                        收入<%=string.IsNullOrEmpty(Model.OrderByName) || Model.OrderByName != "InMoney" ? "" : orderByFlag ? "↑" : "↓"%></label>
                </th>
                <th width="5%">
                    <label class='lblOrderBy' onclick="lbl_OrderBy_Click('OutMoney','<%=orderByFlag?"DESC":"ASC" %>')">
                        支出<%=string.IsNullOrEmpty(Model.OrderByName) || Model.OrderByName != "OutMoney" ? "" : orderByFlag ? "↑" : "↓"%></label>
                </th>
                <th width="33%">备注</th>
                <th width="8%">余额</th>
            </tr>
            <%  if (Model.Details != null && Model.Details.Count() > 0)
            {
                foreach (var item in Model.Details)
                {
                    if (item.Type == UserAccountDetailType.TackMoney)
                        item.Memo = item.Memo == null ? "" : item.Memo.Replace("&&", "管理员说:").Replace("&", "会 员 说:");%>
            <tr id="tritem">
                <td><%=Html.ActionLink(item.LoginName, "AccountDetail", new RouteValueDictionary { { "Serch.LoginName", item.LoginName } }, new RouteValueDictionary { {"class","a_blue"}})%></td>
                <td><%=item.UserType.HasValue ? ((UserType)item.UserType).GetName() : "" %></td>
                <td><%=string.Format("{0:yyyy-MM-dd HH:mm:ss}",item.AddTime) %></td>
                <td><%=((UserAccountDetailType)item.Type).GetName()%></td>
                <td align="right"><%=string.Format("{0:F}",item.InMoney ) %></td>
                <td align="right"><%=string.Format("{0:F}",item.OutMoney ) %></td>
                    <%
                        item.Memo = (!string.IsNullOrEmpty(item.Memo) && !string.IsNullOrEmpty(item.StateText) ? item.Memo + "," + item.StateText : item.Memo + item.StateText) ?? "";
                        var str = item.Memo.Length < 32 ? item.Memo : item.Memo.Substring(0, 28) + "...";
                        str = string.IsNullOrEmpty(str) ? "详情" : str;
                        
                        string act = null;
                        var menu = new {act =Request["act"]?? "AccountDetail", cont =Request["cont"]?? "User", arst =Request["arst"] ?? Model.Serch.Type.ToString() };
                        var ReturnUrl = Url.Action("AccountDetail", "User", Url.Route(new { Model.Serch, Model.PageSize,Model.Page, ReturnUrl = Request["ReturnUrl"] }, menu));
                    
                        switch (item.Type)
                        {
                            case UserAccountDetailType.Play:
                            case UserAccountDetailType.WinMoney:
                            case UserAccountDetailType.WinMoney_Child:
                            case UserAccountDetailType.BackMoney:
                            case UserAccountDetailType.QuashScheme:
                            case UserAccountDetailType.BackMoney_Child:
                                if (item.StateText == SchemeState.Normal.GetName())
                                    act = Url.Action( "Detail", "Scheme", Url.Route(new { SchemeID = item.ID.Replace("-", ""), ReturnUrl }, menu));
                                else
                                    act =Url.Action(  "Detail", "Scheme", Url.Route(new { ID = item.ID.Replace("-", ""), ReturnUrl }, menu));
                                break;
                            case UserAccountDetailType.TackMoney:
                                act = Url.Action("Dispose", "User", Url.Route(new { ID = item.UserID.ToString("N"), tackMoneyID = item.ID, ReturnUrl }, menu));
                                break;
                            case UserAccountDetailType.Other:
                                if (item.StateText == OtherMoneyDetailType.ChaseDetailCancle.GetName()&&item.Info.ContainsKey("TaskID"))
                                    act = Url.Action( "Detail", "ChaseTask", Url.Route(new { ID = item.Info["TaskID"].Replace("-", ""), DetailID = item.ID, ReturnUrl }, menu));
                                else if (item.StateText == OtherMoneyDetailType.ChaseTaskCancle.GetName())
                                    act = Url.Action(  "Detail", "ChaseTask", Url.Route(new { ID = item.ID.Replace("-", ""), ReturnUrl }, menu));
                                else if (item.StateText==OtherMoneyDetailType.BackTimeOutScheme.GetName())
                                    act =Url.Action( "Detail", "Scheme", Url.Route(new { ID = item.ID.Replace("-", ""), ReturnUrl }, menu));
                                break;
                            case UserAccountDetailType.ChaseTask:
                                act = Url.Action("Detail", "ChaseTask", Url.Route(new { ID = item.ID.Replace("-", ""), ReturnUrl }));
                                break;
                        } %>
                <td align="left">
                    <div class="winnumberitem width250">
                        <label title='<%=item.Memo %>'><a <%=act == null ? "" : "href='" + act + "' class='a_blue'" %>><%=str %></a></label>
                    </div>
                </td>
                <td>
                    <%=string.Format("{0:F2}",item.Money) %>
                </td>
            </tr>
            <%} %>
            <tr>
                <td>
                    <font color="red">合计</font>
                </td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td align="right">
                    <%=(Model.SumDetail.InMoney ?? 0d).ToString("C")%>
                </td>
                <td align="right">
                    <%=(Model.SumDetail.OutMoney ?? 0d).ToString("C")%>
                </td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td colspan="8">
                    <%=Html.Pager(Model.Page.Value, Model.PageSize, Model.SumCount, "Page", Url.Route(new { Model.Serch,Model.OrderByName,Model.OrderByType, Model.PageSize}, new {returnUrl=Request["ReturnUrl"], act = Request["act"], cont = Request["cont"], arst = Request["arst"] }), "PageSize")%>
                </td>
            </tr>
            <%}
            else
            {%>
            <tr>
                <td colspan="8">
                    无记录！
                </td>
            </tr>
            <%} %>
        </table>
        <%if (Request["ReturnUrl"] != null)
      {%>
        <a class="a_blue" href='<%=Request["ReturnUrl"] %>'>&gt;&gt;返回</a>
        <%} %>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="StyleAndScript" runat="server">
    <style type="text/css">
        .lblOrderBy{ border-bottom:1px solid #fff; cursor:pointer;}
    </style>
    <script src='<%=Url.Content("~/Scripts/jquery.metadata.js") %>' type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#serchreportform").validate();
            $("#report #tritem:odd").addClass("supersede");
        });
        function lbl_OrderBy_Click(orderByName, orderByType) {
            document.location.href = '<%=Url.Action("AccountDetail", Url.Route(new {Model.Serch,Model.PageSize}, new {returnUrl=Request["ReturnUrl"], act = Request["act"], cont = Request["cont"], arst = Request["arst"] }))%>&OrderByName=' + orderByName + '&OrderByType=' + orderByType;
        }
    </script>
</asp:Content>
